package stat;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

public class MeanDownloadTime {

	/**
	 * @param args
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {	
//		String file = "scripts/gnuplot/logs/stat_rarest_first.log";
//		String file = "scripts/gnuplot/logs/stat_sliding_window.log";
		String file = "scripts/gnuplot/logs/stat_segments.log";
		float res = 0;

		//read log
		Map map = LogReader.getMap(file);
		
		//calculate mean downlaod time
		for(Object peer : map.keySet()) { //each peer
			ArrayList<LogReaderLine> lines = (ArrayList<LogReaderLine>) map.get((String)peer);
			res += lines.get(lines.size()-1).getTimestamp() - lines.get(0).getTimestamp();
		}
		
		System.out.println("Mean download time for the file: " + file);
		System.out.println((res/map.size())/(1000) + " seconds");
	}

}
